/**    
 * @package com.liusany.myshop.service 
 * @description : TODO(用一句话描述该包做什么) 
 * @Copyright: Bmcok Corporation 2012    
*/
package com.liusany.myshop.web.admin;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.liusany.myshop.entity.Role;
import com.liusany.myshop.service.RoleService;

/**   
 * @filename ：RoleDetailController.java   
 * @description : TODO(用一句话描述该类做什么) 
 * @version ：   V 1.0
 * @author : liusany
 * @create : 2012-6-1 下午2:31:43  
 * @Copyright: Bmcok Corporation 2012    
 * 
 * Modification History:
 * 	Date			Author			Version			Description
 *--------------------------------------------------------------
 *2012-6-1 下午2:31:43
 */
@Controller
@RequestMapping(value = "/admin/role")
public class RoleDetailController extends BaseCopntroller{

	@Resource
	private RoleService roleService;
	

	@RequestMapping(value = "update/{id}", method = RequestMethod.GET)
	public String updateForm(Model model) {
		List<String> perList = new ArrayList<String>();
		perList.add("aaa");
		model.addAttribute("perList", perList);
		return "admin/role_input";
	}
	
	@RequestMapping(value = "save/{id}", method = RequestMethod.POST)
	public String save(@ModelAttribute("role") Role role,
			RedirectAttributes redirectAttributes,Model model) {
		roleService.saveRole(role);
		redirectUrl = "admin/role/list";
		setRedirectInfo(redirectUrl, "修改权限组" + role.getName() + "成功", model);
		return SUCCESS;
	}
	
	@ModelAttribute("role")
	public Role getRole(@PathVariable("id") Long id) {
		return roleService.get(id);
	}

}
